Skip to content

Conversation

@codegen-sh
Copy link

@codegen-sh codegen-sh bot commented May 17, 2025

User description

This PR updates all examples in the codegen-examples/examples folder to correspond to up-to-date modal deployments:

Summary of Changes

Root-level Deployer Script

  • Added Deployer.sh in the examples root folder that:
    • Shows a list of all available example deployments
    • Allows interactive selection of examples to deploy
    • Executes selected deployments concurrently
    • Provides deployment status and error handling

Individual Example Deploy Scripts

Added deploy.sh scripts to the following examples:

  • linear_webhooks: Updated with proper environment validation and deployment commands
  • ticket-to-pr: Added comprehensive deployment script with environment checks
  • github_checks: Created new deployment script with GitHub token validation
  • swebench_agent_run: Enhanced existing script with better error handling
  • ai_impact_analysis: Added new deployment script for the backend API
  • modal_repo_analytics: Created deployment script for the analytics API
  • snapshot_event_handler: Added deployment script for GitHub event handling

Documentation Updates

  • Updated README.md files with:
    • Detailed deployment instructions
    • Environment variable configuration guides
    • Troubleshooting tips
    • API usage examples (where applicable)
    • Webhook configuration instructions (where applicable)

Deployment Workflow

The new deployment workflow is:

  1. Navigate to the examples directory
  2. Run ./Deployer.sh to see all available examples
  3. Select which examples to deploy
  4. The script handles concurrent deployment and provides status updates

This PR makes it much easier for users to deploy and manage multiple Modal examples.


💻 View my workAbout Codegen

Summary by Sourcery

Provide a unified, interactive deployment workflow and modernize all codegen example projects to use up-to-date Modal and Codegen SDKs.

New Features:

  • Add a root-level Deployer.sh script for interactive, concurrent example deployments
  • Introduce deploy.sh scripts in each example to automate environment validation and Modal deployments

Enhancements:

  • Improve deploy scripts with environment checks, error handling, and credential validation
  • Upgrade example code to the latest Codegen and Modal SDK versions and APIs
  • Consolidate and update dependency configurations in pyproject.toml and package.json

Build:

  • Update package.json release branch settings and specify packageManager

Documentation:

  • Revamp README files across all examples with detailed prerequisites, setup, deployment commands, usage instructions, customization tips, and troubleshooting guides

PR Type

Enhancement, Documentation


Description

  • Add interactive root-level deployment script for all examples

    • Introduce Deployer.sh for concurrent, menu-driven deployments
  • Add and standardize deploy.sh scripts for each example

    • Automate environment checks, Modal authentication, and deployment
    • Generate .env files/templates with credential instructions
  • Modernize and refactor Linear and Ticket-to-PR example code

    • Update to latest Codegen/Modal SDKs and best practices
    • Improve event handling, logging, and environment validation
  • Overhaul and expand example documentation

    • Add/expand README.md files with setup, deployment, and troubleshooting guides
    • Update .env.template files for clarity and completeness

Changes walkthrough 📝

Relevant files
Enhancement
23 files
Deployer.sh
Add interactive root-level deployment script for all examples
+175/-0 
deploy.sh
Add deploy.sh script for AI Impact Analysis example           
+57/-0   
deploy.sh
Add deploy.sh script for Codegen MCP Server example           
+54/-0   
deploy.sh
Add deploy.sh script for Codegen App example                         
+48/-0   
deploy.sh
Add deploy.sh script for Cyclomatic Complexity example     
+48/-0   
deploy.sh
Add deploy.sh script for Deep Code Research example           
+57/-0   
deploy.sh
Add deploy.sh script for Dead Code Deletion example           
+48/-0   
deploy.sh
Add deploy.sh script for Document Functions example           
+51/-0   
deploy.sh
Add deploy.sh script for GitHub Checks example                     
+56/-0   
deploy.sh
Add deploy.sh script for Linear Webhooks example                 
+47/-0   
deploy.sh
Add deploy.sh script for Modal Repo Analytics example       
+48/-0   
deploy.sh
Add deploy.sh script for PR Review Bot example                     
+60/-0   
deploy.sh
Add deploy.sh script for Repo Analytics example                   
+48/-0   
deploy.sh
Add deploy.sh script for Slack Chatbot example                     
+57/-0   
deploy.sh
Add deploy.sh script for Snapshot Event Handler example   
+47/-0   
deploy.sh
Rewrite and enhance deploy.sh for SWEBench Agent Run         
+43/-2   
deploy.sh
Add deploy.sh script for Ticket-to-PR example                       
+47/-0   
webhooks.py
Refactor and modernize Linear webhook event handling         
+89/-11 
app.py
Refactor Ticket-to-PR app for updated SDK and Modal           
+30/-10 
data.py
Update LinearIssueUpdateEvent model for clarity                   
+1/-0     
helpers.py
Refactor helpers for event processing and codebase creation
+58/-69 
pyproject.toml
Update dependencies and add dev extras for Linear Webhooks
+16/-1   
pyproject.toml
Update dependencies and add dev extras for Ticket-to-PR   
+17/-8   
Documentation
7 files
README.md
Add comprehensive README for Linear Webhooks example         
+128/-0 
.env.template
Update .env.template for Linear Webhooks with clearer instructions
+7/-3     
README.md
Add and expand README for Ticket-to-PR example                     
+127/-26
.env.template
Update .env.template for Ticket-to-PR with clearer instructions
+11/-5   
README.md
Rewrite and expand README for GitHub Checks example           
+111/-92
README.md
Rewrite and expand README for Modal Repo Analytics example
+92/-39 
README.md
Rewrite and expand README for Snapshot Event Handler example
+106/-32
Additional files
1 files
package.json +5/-2     

Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @sourcery-ai
    Copy link

    sourcery-ai bot commented May 17, 2025

    Reviewer's Guide

    This PR introduces a unified, interactive deployment workflow for all codegen examples by adding a root-level Deployer script, provisioning per-example deploy scripts with robust environment checks, standardizing and enriching documentation across each example, refactoring Python example apps for improved lifecycle, event handling, and logging, and updating project metadata and dependency declarations for consistency.

    Sequence Diagram for linear_webhooks Lifecycle and Event Handling

    sequenceDiagram
        participant ModalPlatform as "Modal Platform"
        participant LW_Handlers as "LinearEventHandlers Instance"
        participant CG_Linear as "CodegenApp.linear (SDK component)"
        participant LinearService as "Linear Service"
        participant Logger
    
        ModalPlatform ->> LW_Handlers: Instantiate & Invoke @modal.enter()
        activate LW_Handlers
        LW_Handlers ->> CG_Linear: subscribe_all_handlers()
        CG_Linear -->> LW_Handlers: Ack
        deactivate LW_Handlers
        note over ModalPlatform, Logger: Application is live, awaiting Linear events
    
        LinearService ->> LW_Handlers: POST /webhook (LinearEvent: type="Issue")
        activate LW_Handlers
        LW_Handlers ->> LW_Handlers: handle_issue(event)
        LW_Handlers ->> Logger: info("Received Linear Issue event...")
        LW_Handlers -->> LinearService: JSON Response
        deactivate LW_Handlers
    
        LinearService ->> LW_Handlers: POST /webhook (LinearEvent: type="Comment")
        activate LW_Handlers
        LW_Handlers ->> LW_Handlers: handle_comment(event)
        LW_Handlers ->> Logger: info("Received Linear Comment event...")
        LW_Handlers -->> LinearService: JSON Response
        deactivate LW_Handlers
    
        note over ModalPlatform, Logger: ... other events (e.g., generic) can be handled similarly ...
    
        ModalPlatform ->> LW_Handlers: Invoke @modal.exit()
        activate LW_Handlers
        LW_Handlers ->> CG_Linear: unsubscribe_all_handlers()
        CG_Linear -->> LW_Handlers: Ack
        deactivate LW_Handlers
        ModalPlatform ->> LW_Handlers: Destroy instance
    
    Loading

    File-Level Changes

    Change Details Files
    Add root-level interactive Deployer script
    • Displays menu of available examples
    • Handles user selection (individual/all)
    • Executes selected deploy scripts concurrently
    • Summarizes success/failure status
    • Performs preflight checks for Python, Modal CLI, and .env
    codegen-examples/examples/Deployer.sh
    Add per-example deploy.sh scripts
    • Check for Python and Modal installation
    • Validate Modal token and .env presence
    • Install dependencies as needed
    • Invoke the example’s deploy command
    • Provide status messages and exit codes
    codegen-examples/examples/ai_impact_analysis/deploy.sh
    codegen-examples/examples/github_checks/deploy.sh
    codegen-examples/examples/modal_repo_analytics/deploy.sh
    codegen-examples/examples/snapshot_event_handler/deploy.sh
    codegen-examples/examples/linear_webhooks/deploy.sh
    codegen-examples/examples/ticket-to-pr/deploy.sh
    codegen-examples/examples/swebench_agent_run/deploy.sh
    Standardize and enrich example documentation
    • Uniform ‘Prerequisites’, ‘Setup’, ‘Deployment Commands’ sections
    • Detailed environment variable guides
    • Webhook configuration and API usage instructions
    • Customization and troubleshooting tips
    • Additional resource links
    codegen-examples/examples/github_checks/README.md
    codegen-examples/examples/ticket-to-pr/README.md
    codegen-examples/examples/snapshot_event_handler/README.md
    codegen-examples/examples/modal_repo_analytics/README.md
    codegen-examples/examples/linear_webhooks/README.md
    Refactor Linear webhooks example for event handling
    • Create LinearEventHandlers class with enter/exit hooks
    • Add separate handlers for Issue, Comment, and generic events
    • Use typed LinearEvent, LinearIssue, LinearComment
    • Integrate structured logging
    • Ensure subscribe/unsubscribe lifecycle
    codegen-examples/examples/linear_webhooks/webhooks.py
    Improve Ticket-to-PR example app lifecycle and event processing
    • Enhance enter/exit container hooks
    • Switch to LinearEvent and process_update_event pipeline
    • Reset codebase between requests
    • Add logging and PR link comments to Linear issues
    codegen-examples/examples/ticket-to-pr/app.py
    Update project metadata and dependencies
    • Expand semantic-release branches and set packageManager
    • Bump example pyproject Python versions and add dev dependencies
    • Align codegen and modal versions
    • Add optional dev tool dependencies
    package.json
    codegen-examples/examples/ticket-to-pr/pyproject.toml
    codegen-examples/examples/linear_webhooks/pyproject.toml

    Tips and commands

    Interacting with Sourcery

    • Trigger a new review: Comment @sourcery-ai review on the pull request.
    • Continue discussions: Reply directly to Sourcery's review comments.
    • Generate a GitHub issue from a review comment: Ask Sourcery to create an
      issue from a review comment by replying to it. You can also reply to a
      review comment with @sourcery-ai issue to create an issue from it.
    • Generate a pull request title: Write @sourcery-ai anywhere in the pull
      request title to generate a title at any time. You can also comment
      @sourcery-ai title on the pull request to (re-)generate the title at any time.
    • Generate a pull request summary: Write @sourcery-ai summary anywhere in
      the pull request body to generate a PR summary at any time exactly where you
      want it. You can also comment @sourcery-ai summary on the pull request to
      (re-)generate the summary at any time.
    • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
      request to (re-)generate the reviewer's guide at any time.
    • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
      pull request to resolve all Sourcery comments. Useful if you've already
      addressed all the comments and don't want to see them anymore.
    • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
      request to dismiss all existing Sourcery reviews. Especially useful if you
      want to start fresh with a new review - don't forget to comment
      @sourcery-ai review to trigger a new review!

    Customizing Your Experience

    Access your dashboard to:

    • Enable or disable review features such as the Sourcery-generated pull request
      summary, the reviewer's guide, and others.
    • Change the review language.
    • Add, remove or edit custom review instructions.
    • Adjust other review settings.

    Getting Help

    @korbit-ai
    Copy link

    korbit-ai bot commented May 17, 2025

    By default, I don't review pull requests opened by bots. If you would like me to review this pull request anyway, you can request a review via the /korbit-review command in a comment.

    @coderabbitai
    Copy link

    coderabbitai bot commented May 17, 2025

    Important

    Review skipped

    Bot user detected.

    To trigger a single review, invoke the @coderabbitai review command.

    You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


    🪧 Tips

    Chat

    There are 3 ways to chat with CodeRabbit:

    • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
      • I pushed a fix in commit <commit_id>, please review it.
      • Explain this complex logic.
      • Open a follow-up GitHub issue for this discussion.
    • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
      • @coderabbitai explain this code block.
      • @coderabbitai modularize this function.
    • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
      • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
      • @coderabbitai read src/utils.ts and explain its main purpose.
      • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
      • @coderabbitai help me debug CodeRabbit configuration file.

    Support

    Need help? Join our Discord community for assistance with any issues or questions.

    Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

    CodeRabbit Commands (Invoked using PR comments)

    • @coderabbitai pause to pause the reviews on a PR.
    • @coderabbitai resume to resume the paused reviews.
    • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
    • @coderabbitai full review to do a full review from scratch and review all the files again.
    • @coderabbitai summary to regenerate the summary of the PR.
    • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
    • @coderabbitai resolve resolve all the CodeRabbit review comments.
    • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
    • @coderabbitai help to get help.

    Other keywords and placeholders

    • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
    • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
    • Add @coderabbitai anywhere in the PR title to generate the title automatically.

    CodeRabbit Configuration File (.coderabbit.yaml)

    • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
    • Please see the configuration documentation for more information.
    • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

    Documentation and Community

    • Visit our Documentation for detailed information on how to use CodeRabbit.
    • Join our Discord Community to get help, request features, and share feedback.
    • Follow us on X/Twitter for updates and announcements.

    @codegen-sh
    Copy link
    Author

    codegen-sh bot commented May 17, 2025

    I see a check failed - I'm on it! 🫡

    💻 View my work

    @codegen-sh
    Copy link
    Author

    codegen-sh bot commented May 17, 2025

    I'm looking into both failing checks on PR #138 - the pre-commit check and the Mypy check. I'll examine the logs and fix the issues.

    💻 View my work

    @codegen-sh
    Copy link
    Author

    codegen-sh bot commented May 17, 2025

    I'm now looking at the Build & Release check failure (38721669646) on PR #138. I'll examine the logs and fix the issues.

    💻 View my work

    @codegen-sh
    Copy link
    Author

    codegen-sh bot commented May 17, 2025

    ✅ Fixed failing mypy check in this commit. The issue was type errors in the helpers.py file where some variables were not properly cast to their expected types.

    @Zeeeepa Zeeeepa marked this pull request as ready for review May 17, 2025 13:49
    @Zeeeepa Zeeeepa merged commit 4feb18b into develop May 17, 2025
    11 of 17 checks passed
    @korbit-ai
    Copy link

    korbit-ai bot commented May 17, 2025

    By default, I don't review pull requests opened by bots. If you would like me to review this pull request anyway, you can request a review via the /korbit-review command in a comment.

    @codiumai-pr-agent-free
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 No relevant tests
    🔒 Security concerns

    Sensitive information exposure:
    The deploy.sh scripts create template .env files with placeholder values, but the scripts don't check if existing .env files contain actual secrets before overwriting them. This could lead to accidental deletion of configured secrets if a user runs the script multiple times. Additionally, in the Deployer.sh script, environment variables from .env files are loaded into the shell environment, which could potentially expose secrets to subprocesses or logs.

    ⚡ Recommended focus areas for review

    Error Handling

    The event handlers assume that event.data will always have an id property, but this might not be true for all event types or in error cases. Consider adding null checks before accessing event.data.id.

    logger.warning(f"Received non-Issue data for Issue event: {event.action}")
    return {
        "status": "warning",
        "message": f"Received non-Issue data for Issue event: {event.action}",
        "id": event.data.id
    }
    Missing Error Handling

    The handle_webhook function doesn't have any error handling for API calls or agent execution, which could lead to silent failures or incomplete processing of Linear tickets.

    def handle_webhook(self, event: LinearEvent, request: Request):
        """Handle incoming webhook events from Linear"""
        linear_client = LinearClient(access_token=os.environ["LINEAR_ACCESS_TOKEN"])
    
        # Process the event data
        update_event = process_update_event(event.data)
        linear_client.comment_on_issue(update_event.issue_id, "I'm on it 👍")
    
        # Format the query for the agent
        query = format_linear_message(update_event.title, update_event.description)
        agent = CodeAgent(self.codebase)
    
        # Run the agent with the query
        agent.run(query)
    
        # Create a PR with the agent's changes
        pr_title = f"[{update_event.identifier}] " + update_event.title
        pr_body = "Codegen generated PR for issue: " + update_event.issue_url
        create_pr_result = create_pr(self.codebase, pr_title, pr_body)
    
        logger.info(f"PR created: {create_pr_result.model_dump_json()}")
    
        # Comment on the Linear issue with the PR link
        linear_client.comment_on_issue(
            update_event.issue_id, 
            f"I've finished running, please review the PR: {create_pr_result.url}"
        )
    Concurrency Issues

    The script runs deployments concurrently but doesn't properly capture exit codes. The results array is populated with empty strings initially, and the actual exit codes aren't reliably stored.

    results=()
    
    for idx in "${selected_indices[@]}"; do
        example="${examples[$idx]}"
        example_dir="$SCRIPT_DIR/$example"
    
        # Start deployment in background
        (deploy_example "$example_dir" && echo "SUCCESS: $example" || echo "FAILED: $example") &
        pids+=($!)
        results+=("")
    done
    
    # Wait for all deployments to complete
    for i in "${!pids[@]}"; do
        wait "${pids[$i]}"
        results[$i]=$?
    done

    @codiumai-pr-agent-free
    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix potential AttributeError

    The handler is trying to access id property on event.data in the else branch,
    but if event.data is not a LinearIssue, there's no guarantee it has an id
    attribute. This could cause an AttributeError if the data object doesn't have
    this property.

    codegen-examples/examples/linear_webhooks/webhooks.py [30-53]

     @modal.web_endpoint(method="POST")
     @app.linear.event("Issue")
     def handle_issue(self, event: LinearEvent):
         """Handle Linear Issue events
         
         This endpoint will be triggered when an issue is created, updated, or deleted in Linear.
         """
         # Check if the data is an Issue before accessing title
         if isinstance(event.data, LinearIssue):
             issue_title = event.data.title
             logger.info(f"Received Linear Issue event: {event.action} - {issue_title}")
             return {
                 "status": "success",
                 "message": f"Processed Linear Issue event: {event.action}",
                 "issue_id": event.data.id,
                 "issue_title": issue_title
             }
         else:
             logger.warning(f"Received non-Issue data for Issue event: {event.action}")
             return {
                 "status": "warning",
                 "message": f"Received non-Issue data for Issue event: {event.action}",
    -            "id": event.data.id
    +            "id": getattr(event.data, 'id', 'unknown')
             }
    • Apply / Chat
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion correctly identifies a potential AttributeError if event.data is not a LinearIssue and lacks an id attribute. The use of getattr provides a safe way to access the ID, improving robustness.

    Medium
    Add error handling

    The function doesn't handle potential exceptions that might occur during PR
    creation or agent execution. If any step fails, the function will crash without
    providing feedback to the Linear issue, leaving users without any indication of
    what went wrong.

    codegen-examples/examples/ticket-to-pr/app.py [43-76]

     @modal.web_endpoint(method="POST")
     @app.linear.event("Issue", should_handle=has_codegen_label)
     def handle_webhook(self, event: LinearEvent, request: Request):
         """Handle incoming webhook events from Linear"""
         linear_client = LinearClient(access_token=os.environ["LINEAR_ACCESS_TOKEN"])
     
    -    # Process the event data
    -    update_event = process_update_event(event.data)
    -    linear_client.comment_on_issue(update_event.issue_id, "I'm on it 👍")
    +    try:
    +        # Process the event data
    +        update_event = process_update_event(event.data)
    +        linear_client.comment_on_issue(update_event.issue_id, "I'm on it 👍")
     
    -    # Format the query for the agent
    -    query = format_linear_message(update_event.title, update_event.description)
    -    agent = CodeAgent(self.codebase)
    +        # Format the query for the agent
    +        query = format_linear_message(update_event.title, update_event.description)
    +        agent = CodeAgent(self.codebase)
     
    -    # Run the agent with the query
    -    agent.run(query)
    +        # Run the agent with the query
    +        agent.run(query)
     
    -    # Create a PR with the agent's changes
    -    pr_title = f"[{update_event.identifier}] " + update_event.title
    -    pr_body = "Codegen generated PR for issue: " + update_event.issue_url
    -    create_pr_result = create_pr(self.codebase, pr_title, pr_body)
    +        # Create a PR with the agent's changes
    +        pr_title = f"[{update_event.identifier}] " + update_event.title
    +        pr_body = "Codegen generated PR for issue: " + update_event.issue_url
    +        create_pr_result = create_pr(self.codebase, pr_title, pr_body)
     
    -    logger.info(f"PR created: {create_pr_result.model_dump_json()}")
    +        logger.info(f"PR created: {create_pr_result.model_dump_json()}")
     
    -    # Comment on the Linear issue with the PR link
    -    linear_client.comment_on_issue(
    -        update_event.issue_id, 
    -        f"I've finished running, please review the PR: {create_pr_result.url}"
    -    )
    -    
    -    # Reset the codebase for the next request
    -    self.codebase.reset()
    +        # Comment on the Linear issue with the PR link
    +        linear_client.comment_on_issue(
    +            update_event.issue_id, 
    +            f"I've finished running, please review the PR: {create_pr_result.url}"
    +        )
    +        
    +    except Exception as e:
    +        logger.error(f"Error processing Linear issue: {str(e)}")
    +        linear_client.comment_on_issue(
    +            update_event.issue_id,
    +            f"❌ Error creating PR: {str(e)}"
    +        )
    +    finally:
    +        # Reset the codebase for the next request
    +        self.codebase.reset()
     
         return {"status": "success"}
    • Apply / Chat
    Suggestion importance[1-10]: 3

    __

    Why: The suggestion correctly highlights missing error handling for a complex operation. However, the improved_code's except block is flawed: it can cause a NameError if update_event is not set due to an earlier failure, making its error reporting unreliable.

    Low
    • More

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants